package com.gms.controller.repairmanager;/*
@author jianghai
@data 2021 - 21:15
*/

import com.gms.entity.Repair.Repair;
import com.gms.entity.equipment.Equipment;
import com.gms.service.equipmanager.EquipmentService;
import com.gms.service.repairmanager.RepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/repair")
public class RepairController {

    @Autowired
    private RepairService repairService;
    @Autowired
    private EquipmentService equipmentService;

    @RequestMapping("/torepair")
    public String toRepair(Model model) {
        List<Repair> repairs = repairService.ListRepair();
        model.addAttribute("repairs",repairs);
        return "RepairOrder";
    }

    @RequestMapping("/repair")
    public String repair(Repair repair) {
        repairService.insertRepair(repair);
        return "";
    }

    @RequestMapping("/update")
    public String string(Integer repairid) {
        repairService.updateRepair(repairid);
        Repair repair = repairService.selectById(repairid);
        Equipment equipment = equipmentService.queryByName(repair.getEtypename());
        equipment.setStatus("1");   //表示未租借
        equipmentService.alterEquipment(equipment);
        return "redirect:/repair/torepair";
    }

}
